<template>
  <!-- 移除全局发布弹框组件，改为在具体页面中处理 -->
</template>

<script setup>
import { onLaunch } from '@dcloudio/uni-app';
import { ShoproInit } from './sheep';

import * as RongIMLib from '@rongcloud/imlib-next';
import { RCKitStoreInstaller } from '@rongcloud/imkit-store';

onLaunch(() => {
  ShoproInit();

  // 隐藏原生TabBar（使用自定义TabBar时）
  // #ifdef APP-PLUS
  setTimeout(() => {
    uni.hideTabBar({
      animation: false
    });
  }, 100);
  // #endif
  
  const config = {
  	// 从融云开发者后台获取 appkey
  	appkey: 'pvxdm17jpwibr',
  	// 从融云开发者后台获取临时 token
  	token: 'H6CWDkr0gQe1/Ur2Mc9iie4NvAylVHKsAYpTpwSJmEg=@4x5h.cn.rongnav.com;4x5h.cn.rongcfg.com',
  };
  
  uni.$RongIMLib = RongIMLib;
  
  // lib 初始化
  uni.$RongIMLib.init({
  	appkey: config.appkey,
  });
  
  // Kit store 初始化
  const store = RCKitStoreInstaller({ logLevel: 1 });
  uni.$RongKitStore = store;
  
  // 连接 IM
  uni.$RongIMLib.connect(config.token).then((res) => {
  	const { code, data } = res;
  	if (code !== uni.$RongIMLib.ErrorCode.SUCCESS) {
  		uni.showToast({
  			title: `登录失败 code: ${code}`, icon: 'none',
  		});
  	}
  });

  // 添加专门的中间按钮点击监听器
  setTimeout(() => {
    uni.onTabBarMidButtonTap(() => {
      console.log('中间特殊按钮被点击')
      // 触发全局事件，让首页显示发布弹框
      uni.$emit('showPublishModal')
    })
  }, 500);
});
</script>

<style lang="scss">
  @import '@/sheep/scss/index.scss';
</style>